#!/bin/bash

#1.验证JDK是否已经安装
if type -p java; then
   echo "Java has been installed."
   exit 0
else
#2.安装JDK
   tar -zxvf ./jdk-8u171-linux-x64.tar.gz -C /usr/local/
   mv /usr/local/jdk1.8.0_171  /usr/local/javaJDK
#3.设置环境变量
   echo 'export JAVA_HOME=/usr/local/javaJDK'>> /etc/profile
   echo 'export JRE_HOME=${JAVA_HOME}/jre'>> /etc/profile
   echo 'export CLASSPATH=.:${JAVA_HOME}/lib:${JRE_HOME}/lib'>> /etc/profile
   echo 'export PATH=${JAVA_HOME}/bin:$PATH' >> /etc/profile
#4.使配置生效
   source /etc/profile
   echo "setting path successful."
   java -version
   echo "installed successful."

fi
